package com.zzyl.service.impl.handler;

import com.zzyl.entity.Resource;
import com.zzyl.vo.TreeItemVo;

import java.util.List;
import java.util.stream.Collectors;

public abstract class ResourceFilterHandler {

    public List<Resource> listResource(List<Resource> allList, String id){
        List<Resource> list = allList.stream().filter(item -> {
            //遍历所有的菜单数据
            if (item.getParentResourceNo().equals(id)) {
                return true;
            } else {
                return false;
            }
        }).collect(Collectors.toList());

        return list;
    }

    public List<TreeItemVo> parseItemVo(List<Resource> list){
        List<TreeItemVo> treeItemVoList = list.stream().map(i -> {
            TreeItemVo v = new TreeItemVo();
            v.setId(i.getResourceNo());
            v.setLabel(i.getResourceName());
            return v;
        }).collect(Collectors.toList());

        return treeItemVoList;
    }

    /**
     *
     * @param allList 所有的菜单数据
     * @param root 根节点
     */
    public abstract void filter(List<Resource> allList, TreeItemVo root, String parentResourceNo);
}
